var FADE_SPEED   = 0.25;
var FADERS = new Array();

function Fader(imageId)
{
	this.imageId = imageId;
	this.index = 0;
	this.rotateSpeed = 3000;	//Msecs
	this.fadeSpeed	 = 0.25		//secs
	
	this.srcs = new Array();
	this.links = new Array();
	this.titles = new Array();
}
Fader.prototype.Add = function(src, link, title)
{
	this.srcs.push(src);
	this.links.push(link);
	this.titles.push(title);
}
Fader.prototype.Next = function()
{
	this.index++;
	if (this.index >= this.srcs.length)
		this.index = 0;
}

function OnLoadEvent() 
{
	for (var i=0; i<FADERS.length; i++)
	{
		var fader = FADERS[i];
		window.setTimeout("Preload('" + fader.imageId + "')", 1000); 
		window.setInterval("ShowNext('" + fader.imageId + "')", fader.rotateSpeed); 
	}
}
function GetFader(imageId)
{
	for (var i=0; i<FADERS.length; i++)
		if (FADERS[i].imageId == imageId)
			return FADERS[i];
	return null;
}
function Preload(imageId)
{
	var fader = GetFader(imageId);
	if (null == fader)
		return;

	var srcs = fader.srcs;
	for (var j=0; j<srcs.length; j++)
	{	
		var img = new Image();
		img.src = srcs[j];
	}
}
function ShowNext(imageId)
{
	var fader = GetFader(imageId);
	if (null == fader)
		return;
	fader.Next();
	ShowImage(fader);
}
function OnImageClick(imageId)
{
	var fader = GetFader(imageId);
	var link = fader.links[fader.index];
	if (null != link && '' != link)
		window.open(link, '_duncan');
}
function ShowImage(fader)
{
	var img = document.getElementById(fader.imageId);
	if (null == img)
		return;

	if (document.all)
	{
		img.style.filter="blendTrans(duration=" + fader.fadeSpeed + ")";
		img.filters.blendTrans.Apply();
	}
	
	img.src = fader.srcs[fader.index];
	img.title = fader.titles[fader.index];
	img.alt = fader.titles[fader.index];

	var span = document.getElementById('ImageCaption');
	if (null != span)
	{ span.innerText = 'Image ' + img.title; }

	if (document.all)
	{
		img.filters.blendTrans.Play()
	}
}
